package com.ly.hotel.broadcast;


import com.ly.hotel.adaptor.HardwareInterface;
import com.ly.hotel.common.MyApplication;
import com.ly.hotel.util.ToastUtil;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

/**
 * @Description: 通过BroadcastReceiver重启当前页面，实现语言切换
 * @author HanleyTowne
 * @email  tanghly@gmail.com
 * @date   2012-7-27下午6:05:50
 * @Google+ http://gplus.to/hanleytowne 
 */
public class MyMuteReceiver extends BroadcastReceiver {
	private static int lastVolume = 0;
	private static long lastClickTime;
    public static boolean isFastBroadcast() {
            long time = System.currentTimeMillis();
			long timeD = time - lastClickTime;
            if (timeD >= 0 && timeD <= 800) {
                return true;
            } else {
                lastClickTime = time;
                return false;
            }
    }
	@Override
	public void onReceive(Context context, Intent intent) {
		if(!isFastBroadcast()){
			Log.v("mute", "收到静音按键");
			if(HardwareInterface.getVolume() != 0){
				lastVolume = HardwareInterface.getVolume();
				HardwareInterface.setVolume(0);
				ToastUtil.showShortToastCoustom(MyApplication.getContext(), "静音", Toast.LENGTH_LONG,0);
			} else {
				HardwareInterface.setVolume(lastVolume);
				ToastUtil.showShortToastCoustom(MyApplication.getContext(), "解除静音", Toast.LENGTH_LONG,0);
			}
		}else{
			Log.v("mute", "忽略收到的重复静音按键广播");
		}
	}

}
